﻿@page "/login"
@layout BaseLayout
@inherits BaseComponentBase
@namespace ThingsGateway.Admin.Blazor
@using BlazorComponent;
@using Furion.DataEncryption;
@using Masa.Blazor.Presets;
@using ThingsGateway.Admin.Application;
@using ThingsGateway.Core.Extension;
@if (IsMobile)
{
    <MCard @onkeydown=Enter Height=@("100%")>
        @GetLoginCore()
    </MCard>
}
else
{
    <MRow NoGutters Style="height:100%">
         <MCol Md=7 Cols=12>
             <MSheet Elevation=1 Style="width:100%; height:100%;" Class="d-flex align-start flex-column mb-6">
                 <div class="d-flex align-center ml-12 mt-12">
                     <MAvatar Size="40" Color="teal">
                         <span class="white--text text-h6">@BlazorAppInfoConfigs.Current.Title?.GetNameLen2()</span>
                    </MAvatar>
                    <h4>@BlazorAppInfoConfigs.Current.Title</h4>
                </div>
                <div class="d-flex align-center ml-12 mt-12 mb-auto">
                    <h5>@BlazorAppInfoConfigs.Current.Remark</h5>
                </div>
                <div class="d-flex align-center pa-2" style="width:100%;height:100%;">
                    <MImage Src=@(BlazorAppService.DefaultResourceUrl+"images/login-left.svg")></MImage>
                </div>
            </MSheet>

        </MCol>

        <MCol Md=5 Cols=12 Align="AlignTypes.Center">
            <MRow Md=6 Cols=12 Justify="JustifyTypes.Center" Align="AlignTypes.Center">
                <MCard Class="px-16 py-12" @onkeydown=Enter>
                    @GetLoginCore()
                </MCard>
            </MRow>
        </MCol>

    </MRow>

}

@code {

    RenderFragment GetLoginCore()
    {
        RenderFragment ViewSubMenu =
    @<div class="mt-2 px-2 py-1 mx-auto text-center my-auto">
        <MAvatar Size=80>
            <MImage Src=@_userLogoUrl>
            </MImage>
        </MAvatar>
        <h5 class="mt-2 mb-12">@_welcome 👋</h5>
        <MTextField TValue="string"
                    Outlined
                    HideDetails="@("auto")"
                    @bind-Value=@_loginModel.Account Label=@AppService.I18n.T("账号")>
        </MTextField>
        <MTextField TValue="string"
                    Class="mt-5"
                    Type="@(_showPassword ? "text" : "password")"
                    AppendIcon="@(_showPassword ? "mdi-eye" : "mdi-eye-off")"
                    OnAppendClick="()=>_showPassword = !_showPassword"
                    Outlined
                    HideDetails="@("auto")"
                    @bind-Value=@_password Label=@AppService.I18n.T("密码")>
        </MTextField>
        @if (_showCaptcha)
    {
        <PImageCaptcha @ref=_captcha
                       @bind-Value="_captchaValue" Label=@AppService.I18n.T("验证码")
                       TextFieldClass="mt-5 mx-auto"
                       Outlined Dense
                       OnRefresh="RefreshCode"
                       ErrorMessage=@AppService.I18n.T("验证码错误")>
        </PImageCaptcha>
    }
        <MButton Class="mt-8 rounded-4" OnClick=LoginAsync Height=45 Width=@("100%") Color="primary">@AppService.I18n.T("登录")</MButton>
    </div>
        ;
        return ViewSubMenu;
    }
}
